<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>角色管理</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}"/>
</head>
<body>
<div class="layui-row">
    <div class="layui-col-md3">
        <ul id="roleGroupTree"></ul>
    </div>
    <div class="layui-col-md9">
        <input hidden="hidden" id="nodeId" name="nodeId">
        <div class="demoTable">
            <button id="roleGroupAdd" class="layui-btn" data-type="add">新增</button>
        </div>
        <table id="roleList" lay-filter="roleList"></table>
    </div>
</div>

<script type="text/html" id="barRole">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="user"><li class="layui-icon">&#xe613;配置人员</li></a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail"><li class="layui-icon">&#xe628;配置功能</li></a>
</script>

<script th:src="@{/static/layui/layui.all.js}"></script>
<script type="text/javascript" th:inline="javascript">

    var ctxPath = /*[[@{/}]]*/ '';
    layui.use(['table','form','tree'],function () {
        var table = layui.table,tree = layui.tree,form = layui.form,$ = layui.$;

        $.get({
            url: ctxPath + "/roleGroup/tree",
            success:function (data) {

                if(data.status){
                    initRoleGroupTree(data.data);
                }

            }
        });

        $("#roleGroupAdd").on('click', function(){
            layer.open({
                title: '角色新增',
                type: 2,
                area: ['600px', '300px'],
                content: ctxPath + '/role/toAdd/' + $("#nodeId").val(),
                end:function(){
                    table.reload('roleList');
                }
            });
        });

        /**
         * 初始化树结构
         * @param data
         */
        function initRoleGroupTree(data) {
            tree({
                elem: '#roleGroupTree', //传入元素选择器
                nodes: data,
                click:function (node) {
                    $("#nodeId").val(node.id);
                    table.render({
                        elem: '#roleList',
                        height: 700,
                        page: true, //开启分页
                        url: ctxPath + '/role/pageList/' + node.id,
                        cols: [[ //表头
                            {type:'numbers',fixed: 'left'},
                            {type: 'checkbox',fixed: 'left'},
                            {field: 'roleCode',align:'center', title: '编码'},
                            {field: 'roleName',align:'center', title: '名称'},
                            {fixed: 'right',align:'center', toolbar: '#barRole'}
                        ]]
                    });
                }
            });
        }
    });

</script>
</body>
</html>